<template>
  <div style="padding:20px">
      <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item prop="keyword" label="关键字:">
        <el-input
          v-model="queryParams.keyword"
          placeholder="请输入关键字"
          clearable
          style="width: 240px"
        />
      </el-form-item>

      <el-form-item prop="status" label="活动状态:">
        <el-select v-model="queryParams.status" placeholder="请选择活动状态" style="width: 240px">
          <el-option label="未开始" value=3 />
          <el-option label="报名中" value=0 />
          <el-option label="活动中" value=1 />
          <el-option label="报名结束" value=4 />
          <el-option label="活动结束" value=2 />
        </el-select>
      </el-form-item>

      <el-form-item prop="time" label="活动报名时间:">
        <el-date-picker
          v-model="time"
          type="datetimerange"
          @change="chooseTime()"
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button
            type="primary"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button size="mini" @click="resetQuery"
            >重置</el-button
          >
      </el-form-item>
    </el-form>
    <div class="box_list">
      <el-row :gutter="10" class="mb8">
      <el-button
      type="primary"
      plain
      icon="el-icon-plus"
      size="mini"
      @click="handleAdd"
      style="margin-bottom: 10px;"
      v-hasPermi="['society:activityUp:index']"
      >活动上传</el-button
      >
      <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>
      <el-table
        :data="activityList"
        style="width: 100%">
        <el-table-column
          prop="id"
          label="序号"
          align="center"
          width="80">
        </el-table-column>
        <el-table-column
          prop="activityName"
          align="center"
          label="活动名称"
          width="160">
        </el-table-column>
        <el-table-column
          prop="activityAddr"
          align="center"
          label="活动地址"
          width="270">
        </el-table-column>
        <el-table-column
          prop="enrollment"
          align="center"
          label="报名人数"
          width="100">
          <template slot-scope="scope">
            <div class="enrollment" title="查看报名人员列表" @click="getMemberList(scope.row.aid)">{{ scope.row.enrollment }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="registration"
          align="center"
          label="报名时间">  
          <template scope="scope">
            {{ scope.row.registrationBeginTime }} - {{ scope.row.registrationEndTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="activityTime"
          align="center"
          label="活动时间">
          <template scope="scope">
            {{ scope.row.activityBeginTime }} - {{ scope.row.activityEndTime }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          align="center"
          label="发布时间"
          width="160">
        </el-table-column>
        <el-table-column
          prop="readingFrequency"
          align="center"
          label="活动状态"
          width="120">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.status == 3">未开始</el-tag>
            <el-tag type="success" v-if="scope.row.status == 0">报名中</el-tag>
            <el-tag type="success" v-if="scope.row.status == 1">活动中</el-tag>
            <el-tag type="warning" v-if="scope.row.status == 2">活动结束</el-tag>
            <el-tag type="warning" v-if="scope.row.status == 4">报名结束</el-tag>
          </template>
        </el-table-column>
        <el-table-column
        label="操作"
        align="center"
        width="120"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="editArticle(scope.row.aid)"
            v-hasPermi="['society:activityEdit:edit']"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="actDeal('begin',scope.row)"
            v-if="scope.row.status == 3"
            v-hasPermi="['society:activityEdit:edit']"
            >提前开始</el-button
          >
          <el-button
            size="mini"
            type="text"
            @click="actDeal('end',scope.row)"
            v-if="scope.row.status == 0"
            v-hasPermi="['society:activityEdit:edit']"
            >提前结束</el-button
          >
        </template>
      </el-table-column>
      </el-table>

      <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </div>   
  </div>
</template>
<script>
import { pageList,updateStatus } from '@/api/society'
export default{
  data(){
    return {
      //查询参数
      queryParams:{
        pageSize:10,
        pageNum:1,
        keyword:'',
        registrationBeginTime:'',
        registrationEndTime:'',
        status:'',
      },
      //时间
      time:'',
      //活动列表
      activityList:[],
      //总条数
      total:0,
      showSearch:true
    }
  },
  created(){
    this.getList()
  },
  methods:{
    getList(){
      let params = {
        ...this.queryParams
      }
      pageList(params).then(res =>{
        if(res.code == 200){
          this.activityList = res.rows
          this.total = res.total
          this.activityList.forEach((item,index)=>{
            this.$set(item, "id", index + 1);
          })
        }
      })
    },
    //时间分割
    chooseTime(){
      this.queryParams.registrationBeginTime = this.time[0]
      this.queryParams.registrationEndTime = this.time[1]
    },
    //编辑文章
    editArticle(data){
      this.$router.push({
          path: "/society/activityEdit",
          query: { key: data },
        });
    },
    //文章上传
    handleAdd(){
      this.$router.push({
          path: "/society/activityUp",
        });
    },
    //查看报名会员
    getMemberList(data){
      this.$router.push({
          path: "/society/participantList",
          query: { key: data },
        });
    },
    //重置表单
    resetQuery() {
      this.queryParams = {
        pageSize:10,
        pageNum:1,
        keyword:'',
        registrationBeginTime:'',
        registrationEndTime:'',
        status:'',
      },
      this.time = ''
      this.getList()
    },
    /** 搜索按钮操作 */
    handleQuery() {
    this.queryParams.pageNum = 1;
    this.getList();
    },
    //活动处理
    actDeal(data,row){
      let status = ''
      if(data == 'begin'){
        status = 0
      }else if(data == 'end'){
        status = 4
      }
      const params = {
          aid:row.aid,
          status:status
        }
      updateStatus(params).then(res=>{
        if(res.code == 200){
          this.$message({
          message: '更改成功',
          type: 'success'
          });
          this.getList()
        }
      })
    }
  }
}
</script>
<style scoped>
.box_list{
  background: white;
  min-height: 645px;
}
.title{
  font-family: Alibaba PuHuiTi;
  font-size: 16px;
}
.enrollment{
  color:#1890FF;
  cursor:pointer;
}
</style>